<?php
/**
 *
 *
 *
 */
namespace Yz\modules\Users;
class Item_User
    extends Item_Default
{


    /** NOTE: required
     *  @var Yz_Descriptor_Interface
     */
    protected static $descriptor;


    /** extending the parent Default item
     *  @var string
     */
    protected static $properties = '
        passwordMD5: { type: string }
    ';


    /*************************
     *      Public methods   *
     *************************/

    /**
     *  @param string
     *  @return this
     *  @throw Yz_User_Exception
     */
    public function verifyPassword($password)
    {
        $password = \Yz_String::testNotEmpty($password);
        if ( $this->matchPassword($password) ) {

        } else {
            $ex = new \Yz_User_Exception();
            throw $ex;
        }
        return $this;
    }

    /**
     *  @param string
     *  @return this
     */
    public function setPassword($password)
    {
        $password = \Yz_String::testNotEmpty($password);
        $this->values['passwordMD5'] = md5($password);
        return $this;
    }


    /**
     *
     */
    protected function matchPassword($password)
    {
        return md5($password) === $this->values['passwordMD5'];
    }

} // class
